package cn.wbnull.springbootdemo.controller;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import javax.naming.Name;

import lombok.Data;

/**
 * 功能描述
 *
 * @author EDZ
 * @since 2022-07-26
 */
class test {
    public static void main(String[] args) {
         ArrayList<Employee> arrayList = new ArrayList<Employee>();
         arrayList.add(new Employee("大壮","上海公司","研发一部",28,3000));
        arrayList.add(new Employee("二牛","上海公司","研发一部",24,4000));
        arrayList.add(new Employee("铁柱","上海公司","研发二部",34,5000));
        arrayList.add(new Employee("翠花","南京公司","测试一部",27,6000));
        arrayList.add(new Employee("玲玲","南京公司","测试二部",21,7000));
//
//        List<Employee> employeeList = arrayList.stream()
//                .filter(employee ->
//                     "上海公司".equals(employee.getWork())
//                ).collect(Collectors.toList());
//        System.out.println(employeeList);
//
//        Map<String,List<Employee>> employeeList2 = arrayList.stream()
//                .filter(employee ->
//                        "上海公司".equals(employee.getWork())
//                ).collect(Collectors.groupingBy(Employee::getSector));
//        System.out.println(employeeList2);
//
//        Integer sum = arrayList.stream().filter(employee -> "上海公司".equals(employee.getWork()))
//                .collect(
//                        Collectors.summingInt(Employee::getSalary
//                        ));
//        System.out.println(sum);
//
//        Optional<Employee> highestSalaryEmployee  = arrayList.stream().filter(employee -> "上海公司".equals(employee.getWork()))
//                .max(Comparator.comparingInt(Employee::getSalary));
//        System.out.println(highestSalaryEmployee.get());
//
        Map<String,Long> count = arrayList.
                stream().
                collect(Collectors.groupingBy(Employee::getWork
                        ,Collectors.counting()));
        System.out.println(count);
//
//        Map<Boolean,Long> count2 = arrayList.
//                stream().
//                collect(Collectors.partitioningBy(e->"上海公司".equals(e.getWork())
//                        ,Collectors.counting()));
//        System.out.println(count2);
//
//        Map<String,Map<String,Long>> count3 = arrayList.
//                stream().
//                collect(Collectors.groupingBy(Employee::getWork
//                        ,Collectors.groupingBy(Employee::getSector,Collectors.counting())));
//        System.out.println(count3);
//
//
//
//
//
//
//
    }
    @Data
    public static class Employee {
        private String name;
        private String work;
        private String sector;
        private int age;
        private int salary;

        public Employee(String name, String work, String sector, int age, int salary) {
            this.name = name;
            this.work = work;
            this.sector = sector;
            this.age = age;
            this.salary = salary;
        }
    }


    public static void main23(String[] args) {
        System.out.println("dadsa");
    }

//    public static void main(String[] args) {
//        ArrayList<String> list = new ArrayList<>();
//        list.add("12");
//        list.add("12");
//        list.add("33");
//        list.add("44");
//         ArrayList<String> arrayList = new ArrayList<>();
//        arrayList.stream().distinct().collect(Collectors.toList());
//            System.out.println(arrayList);
//        }
//        ArrayList<String> arrayList= (ArrayList<String>) list.stream().distinct().collect(Collectors.toList());
//        System.out.println(arrayList);
//        List<String> result = new ArrayList<String>(list.size());
//        for (String str : list) {
//            if (!result.contains(str)) {
//                result.add(str);
//            }
//        }
//        list.clear();
//        list.addAll(result);
//        System.out.println(list);
//        System.out.println(result);
//         List<String> list = Collections.synchronizedList(new ArrayList<>());
//        list.add("practice");
//        list.add("code");
//        list.add("quiz");
//        System.out.println(list);
//        System.out.println(list.stream().collect(Collectors.toList()));
//         ArrayList<String> arrayList = new ArrayList<>();
//        arrayList.add("Google");
//        arrayList.add("Runoob");
//        arrayList.add("Taobao");
//        arrayList.add("Zhihu");
//        Iterator<String> it = arrayList.iterator();
//        System.out.println(it.next());
//        synchronized (list)
//        {
//            Iterator its =list.iterator();
//            while (its.hasNext())
//                System.out.println(its.next());
//        }
//
//        Date date = new Date(2012,1,1);
//        System.out.println(date);
//         Calendar calendar = Calendar.getInstance();
//         calendar.set(2013,1,2);
//        System.out.println(calendar);
//
//    }

}
